package cn.donting.jme.utile;

import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;

public class MathUtil {
    /**
     * PI=90°
     * 弧度转角度
     * @param radian
     * @return
     */
    public static float radianToAngle(float radian) {
        return radian / FastMath.PI * 180;
    }

    /**
     * 角度转弧度
     * @param angle
     * @return
     */
    public static float angleToRadian(float angle) {
        return angle / 180 * FastMath.PI;
    }

    public static boolean  isNaN(float f){
        return Float.isNaN(f) || Float.isInfinite(f);
    }
    public static boolean  isNaN(Vector3f v){
        return isNaN(v.x) || isNaN(v.y) || isNaN(v.z);
    }

    public static Vector3f quaternionToAngles(Quaternion rotation){
        float[] angles = rotation.toAngles(new float[3]);
        return new Vector3f(angles[0] / FastMath.PI * 180, angles[1] / FastMath.PI * 180, angles[2] / FastMath.PI * 180);
    }
    public static Quaternion anglesToQuaternion(Vector3f angles){
        Quaternion q = new Quaternion();
        q.fromAngles(angles.x / 180 * FastMath.PI, angles.y / 180 * FastMath.PI, angles.z / 180 * FastMath.PI);
        return q;
    }
}
